// ml:run = $bin < input
#include <iostream>

using ll = long long;
ll const inf = (1ll) << 44;
ll n, m, k;
ll x, y;
ll up;

void extended_gcd(ll a, ll b, ll & d, ll & x, ll & y)
{
	if (!b) { d = a; x = 1; y = 0; }
	else {
		extended_gcd(b, a % b, d, y, x);
		y -= x * (a/b);
	}
}

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }

ll inverse(ll t, ll p)
{
	ll x, y, d;
	extended_gcd(t, p, d, x, y);
	return (x % p + p) % p;
}

ll calc(int op1, int op2) // x, y
{
    ll tmp = -op2 * y + op1 * x;
    tmp = ((tmp % (2 * n)) + 2 * n) % (2 * n);
    ll g = gcd(gcd(2 * m, 2 * n), tmp);
    ll ta = (2 * m) / g;
    ll tb = tmp / g;
    ll tc = (2 * n) / g;
    if (gcd(ta, tc) != 1) return inf;
    tb = (tb * inverse(ta, tc) ) % tc;
    ll ret = 2 * m * tb + op2 * y;
    if (ret > 0) return ret;
    ret %= (2 * m);
    ret = (ret + 2 * m) % (2 * m);
    return ret;
}

ll work()
{
    ll t1 = std::min(calc(-1, -1), calc(1, -1));
    ll t2 = std::min(calc(-1, 1), calc(1, 1));
    return std::min(t1, t2);
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> n >> m >> k;
    up = inf;
    /* x = 0; y = 0; up = work(); */
    if (n != m) up = lcm(2 * n, 2 * m);
    else up = n;
    x = 0; y = m; up = std::min(up, work());
    x = n; y = 0; up = std::min(up, work());
    x = n; y = m; up = std::min(up, work());
    for (int i = 0; i < k; i++) {
        std::cin >> x >> y;
        ll tmp = work();
        if (tmp >= up)
            std::cout << "-1\n";
        else
            std::cout << tmp << "\n";
    }
}

